package pages;

import java.io.File;
import common.ReadPageXML;

public class BasePage {
	String pageFileName;
	public BasePage(){
		pageFileName = (String)getClassName();
		System.out.println("Calling class name is " + pageFileName);
		
		//form the xml file path
		File directory = new File (".");
		String absPath = null;
		String path = null;  
		try {
			System.out.println ("Current directory's canonical path: " 
					+ directory.getCanonicalPath()); 
			System.out.println ("Current directory's absolute  path: " 
					+ directory.getAbsolutePath());
			absPath = new String(directory.getAbsolutePath());
			path = new String(directory.getPath());
			System.out.println("Path = " + path);
		}catch(Exception e) {
			 	System.out.println("Exceptione is ="+e.getMessage());
		}
         
		String temp [] = null;
		temp = absPath.split("\\.");
		String xmlPath = temp[0] + "src\\Pages\\xml\\" + pageFileName + ".xml";
		System.out.println("Xml file path is => " + xmlPath);

		//call the function to parse the xml 
		ReadPageXML xml_parser = new ReadPageXML();
		xml_parser.parseXML(xmlPath);
		
		
		
		
	}

		
	
	 /**
     * Get the calling class's class name.
     * 
     * @return The calling class's class name.
     */
    public static Object getClassName() {
   //     String qualifiedClassName = new Exception().getStackTrace()[1].getClassName();
   //     String what = new Exception().getStackTrace()[0].getClassName();
   //     System.out.println("What 1 = " + what);
   //     what = new Exception().getStackTrace()[2].getClassName();
   //     System.out.println("What 2 = " + what);
        String qualifiedClassName = new Exception().getStackTrace()[2].getClassName();

        return qualifiedClassName.substring(qualifiedClassName.lastIndexOf('.') + 1, qualifiedClassName.length());
    }

    /**
     * Get the calling class's package name.
     * 
     * @return The calling class's package name.
     */
    public static Object getPackageName() {
        String qualifiedClassName = new Exception().getStackTrace()[1].getClassName();
        return qualifiedClassName.substring(0, qualifiedClassName.lastIndexOf('.'));
    }
}
